package com.frkj.yuan.fragment.order;

import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alipay.sdk.app.PayTask;
import com.frkj.yuan.R;
import com.frkj.yuan.activity.AgainYuYueJiuzhenPersonActivity;
import com.frkj.yuan.activity.MyDianPingActivity;
import com.frkj.yuan.activity.OrderCommentActivity;
import com.frkj.yuan.activity.ServiceAccoMpanyingActivity;
import com.frkj.yuan.activity.UserLoginActivity;
import com.frkj.yuan.activity.WaitOrderMapActivity;
import com.frkj.yuan.activity.YuyueSuccessAcitivity;
import com.frkj.yuan.api.bean.OrderMsgBean;
import com.frkj.yuan.api.bean.OrderPayorderMsgBean;
import com.frkj.yuan.api.category.OrderAllMsgCategory;
import com.frkj.yuan.api.presenter.OrderListAllPresenter;
import com.frkj.yuan.base.BaseBean;
import com.frkj.yuan.base.BaseFragment;
import com.frkj.yuan.dialog.LoadingDialog;
import com.frkj.yuan.dialog.LoginOutDialog;
import com.frkj.yuan.dialog.OnQuiteDialogClickListener;
import com.frkj.yuan.dialog.RoundCornerDialog;
import com.frkj.yuan.fragment.home.PayResult;
import com.frkj.yuan.main.ConstantStaticUrl;
import com.frkj.yuan.utils.HttpNetworkConnectUtils;
import com.frkj.yuan.utils.SPUtils;
import com.frkj.yuan.utils.ToastUtil;
import com.frkj.yuan.view.RecyclerViewLayoutManager;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static android.content.Context.MODE_PRIVATE;

/**
 * 作者：菲菲 on 2022/2/17 10:29
 * company：丰蓉信息科技有限公司
 */
public class OrderAllFragment extends BaseFragment implements OrderAllMsgCategory.View, OnRefreshListener {
    @BindView(R.id.base_refresh_recycler)
    RecyclerView mRecyclerViews;
    private long mUserId;
    @BindView(R.id.relat_empty)
    RelativeLayout mEmptyLayout;
    @BindView(R.id.base_refresh)
    SmartRefreshLayout smartRefreshLayout;
    private String mToken;
    private int pageNumber = 1;
    private List<OrderMsgBean.OrderMsgBeanData.OrderMsgBeanDataList> mlist = new ArrayList<>();
    private JSONObject result;
    private static final int SDK_PAY_FLAG = 1;
    private OrderListAllPresenter mPresenter;
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    PayResult payResult = new PayResult((String) msg.obj);
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();
                    Log.e("resultInfo", resultInfo + "===resultStatus==" + resultStatus);
                    if (TextUtils.equals(resultStatus, "9000")) {
                        ToastUtil.showToastSUCCESS(getActivity(), "支付成功");
                        Bundle bundle = new Bundle();
                        bundle.putLong("hospitalId", hospitalId);
                        bundle.putString("hospitalName", hospitalName);
                        bundle.putString("orderId", String.valueOf(orderId));
                        openActivityWitchAnimation(WaitOrderMapActivity.class, bundle);
                    } else {
                        // 判断resultStatus 为非"9000"则代表可能支付失败
                        // "8000"代表支付结果因为支付渠道原因或者系统原因还在等待支付结果确认，最终交易是否成功以服务端异步通知为准（小概率状态）
                        if (TextUtils.equals(resultStatus, "8000")) {
                            ToastUtil.showToastINFO(getActivity(), "支付结果确认中");
                        } else {
                            ToastUtil.showToastINFO(getActivity(), "用户取消支付");
                        }

                    }
                    break;
                }
            }
        }
    };
    private LoadingDialog mpcd;
    private OrderAllListAdapter mAdapter;
    private boolean isLoading = false;
    private long hospitalId;
    private String hospitalName;
    private long orderId;
    private LoginOutDialog dialog;

    @Override
    public void onResume() {
        super.onResume();
        smartRefreshLayout.autoRefresh();
    }

    // TODO: 2022/6/8 fragment 来回切换自动刷新列表数据
    @Override
    public void onHiddenChanged(boolean hidden) {
        // TODO Auto-generated method stub
        super.onHiddenChanged(hidden);
        if (!hidden) {
            smartRefreshLayout.autoRefresh();
        }
    }

    //加上这个方法可能会执行两次刷新操作,可以去掉试试
    public int getLayoutResource() {
        return R.layout.base_refresh_recycler_view;
    }

    @Override
    public void initLayoutView() {
        mpcd = new LoadingDialog(getActivity());
        mpcd.show();
        mAdapter = new OrderAllListAdapter(mlist);
        mAdapter.setDatas(mlist);
        mRecyclerViews.setAdapter(mAdapter);
        mToken = (String) SPUtils.get(getActivity(), ConstantStaticUrl.mToken, "");
        RecyclerViewLayoutManager.setLinearVerticalManager(getActivity(), mRecyclerViews);
        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("First", MODE_PRIVATE);
        mUserId = sharedPreferences.getLong(ConstantStaticUrl.userId, 0);
        mPresenter = new OrderListAllPresenter(this);
        SetPersenter(mPresenter);
        result = new JSONObject();
        try {
            result.put("userId", mUserId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        if (!HttpNetworkConnectUtils.isNetworkConnected(getActivity())) {
            ToastUtil.showToastERROR(getActivity(), "网络不给力,请稍后重试");
        } else {
            mPresenter.getOrderList(pageNumber, mToken, result.toString());
        }
        smartRefreshLayout.setOnRefreshListener(this);
    }

    @Override
    public void getOrderList(OrderMsgBean order) {
        if (order.getCode() == ConstantStaticUrl.SUCCESS_CODE) {
            if (order.getData() != null && order.getData().getList().size() > 0) {
                if (pageNumber == 1) {
                    if (isLoading) {
                        isLoading = false;
                    } else {
                        mlist.clear();
                    }
                    mlist.addAll(order.getData().getList());
                    mAdapter.setDatas(order.getData().getList());
                } else {
                    mlist.addAll(mlist.size(), order.getData().getList());
                    mAdapter.add(order.getData().getList());
                }
                mEmptyLayout.setVisibility(View.GONE);
                mRecyclerViews.setVisibility(View.VISIBLE);
            } else {
                if (isLoading) {
                    isLoading = false;
                } else {
                    mEmptyLayout.setVisibility(View.VISIBLE);
                    mRecyclerViews.setVisibility(View.GONE);
                }
            }
        } else if (order.getCode() == 401) {
            if (dialog == null) {
                dialog = new LoginOutDialog(getActivity());
            }
            if (dialog != null && !dialog.isShowing()) {
                dialog.show();
            }
            dialog.findViewById(R.id.circler_delete).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
            dialog.findViewById(R.id.to_login).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    openActivityWitchAnimation(UserLoginActivity.class);
                    SPUtils.clear(getActivity());
                    getActivity().finish();
                    dialog.dismiss();
                }
            });
        } else {
            ToastUtil.showToastINFO(getActivity(), order.getMsg());
        }
        mpcd.dismiss();
    }

    @Override
    public void getPayOrderMsg(OrderPayorderMsgBean payorder) {
        if (payorder.getCode() == ConstantStaticUrl.SUCCESS_CODE) {
            final Runnable payRunnable = new Runnable() {
                @Override
                public void run() {
                    // 构造PayTask 对象
                    PayTask alipay = new PayTask(getActivity());
                    // 调用支付接口，获取支付结果
                    String result = alipay.pay(payorder.getData().getOrderStr(), true);
                    Message msg = new Message();
                    msg.what = SDK_PAY_FLAG;
                    msg.obj = result;
                    Log.e("result", result);
                    mHandler.sendMessage(msg);
                }
            };
            Thread payThread = new Thread(payRunnable);
            payThread.start();
        } else {
            ToastUtil.showToastINFO(getActivity(), payorder.getMsg());
        }
        mpcd.dismiss();
    }

    @Override
    public void getTuikuanMoney(BaseBean tuikuan) {
        if (tuikuan.getCode() == ConstantStaticUrl.SUCCESS_CODE) {
            ToastUtil.showToastSUCCESS(getActivity(), "退款成功");
            smartRefreshLayout.autoRefresh();
        } else {
            ToastUtil.showToastINFO(getActivity(), tuikuan.getMsg());
        }
        mpcd.dismiss();
    }

    @Override
    public void getCancle(BaseBean order) {

        if (order.getCode() == ConstantStaticUrl.SUCCESS_CODE) {
            ToastUtil.showToastSUCCESS(getActivity(), "订单取消成功");
            mAdapter.notifyDataSetChanged();
            smartRefreshLayout.autoRefresh();
        } else {
            ToastUtil.showToastERROR(getActivity(), order.getMsg());
        }
        mpcd.dismiss();
    }

    @Override
    public void getDeleteOrder(BaseBean delete) {
        if (delete.getCode() == ConstantStaticUrl.SUCCESS_CODE) {
            ToastUtil.showToastSUCCESS(getActivity(), "订单删除成功");
            smartRefreshLayout.autoRefresh();
        } else {
            ToastUtil.showToastERROR(getActivity(), delete.getMsg());
        }
        mpcd.dismiss();
    }

    @Override
    public void SetPersenter(Object persenter) {
    }

    @Override
    public void OnShowErrorMsg(String mErrorMsg) {
        ToastUtil.showToastERROR(getActivity(), mErrorMsg);
        mpcd.dismiss();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        pageNumber = 1;
        mPresenter.getOrderList(pageNumber, mToken, result.toString());
        smartRefreshLayout.finishRefresh(500);
    }

    public class OrderAllListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        private List<OrderMsgBean.OrderMsgBeanData.OrderMsgBeanDataList> mlist;

        public OrderAllListAdapter(List<OrderMsgBean.OrderMsgBeanData.OrderMsgBeanDataList> mlist) {
            this.mlist = mlist;
        }

        public void add(List<OrderMsgBean.OrderMsgBeanData.OrderMsgBeanDataList> addMessageList) {
            //增加数据
            int position = mlist.size();
            mlist.addAll(position, addMessageList);
            notifyItemInserted(position);
        }

        /***
         * 加载列表集合
         * @param mylist
         */
        public void setDatas(List<OrderMsgBean.OrderMsgBeanData.OrderMsgBeanDataList> mylist) {
            mlist.clear();
            mlist.addAll(mylist);
            notifyDataSetChanged();
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.order_item_view, null);
            OneItemHolder viewHolder = new OneItemHolder(view);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
            //如果当前的 viewHolder 属于 OneItemHolder 则执行
            ((OneItemHolder) viewHolder).tuikuan_title.setText("订单号 : " + mlist.get(position).getOrderNo());
            ((OneItemHolder) viewHolder).mOrderNo.setText("订单号 : " + mlist.get(position).getOrderNo());
            ((OneItemHolder) viewHolder).order_number.setText("订单号 : " + mlist.get(position).getOrderNo());
            ((OneItemHolder) viewHolder).order_fuwu_zhong.setText("订单号 : " + mlist.get(position).getOrderNo());
            ((OneItemHolder) viewHolder).cancel_title.setText("订单号 : " + mlist.get(position).getOrderNo());
            ((OneItemHolder) viewHolder).complet_order.setText("订单号 : " + mlist.get(position).getOrderNo());
            ((OneItemHolder) viewHolder).yifuk_title.setText("订单号 : " + mlist.get(position).getOrderNo());
            if (mlist.get(position).getOrderStatus() == 1) {
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.GONE);
            } else if (mlist.get(position).getOrderStatus() == 2) {
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.GONE);
            } else if (mlist.get(position).getOrderStatus() == 3) {
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.GONE);
            } else if (mlist.get(position).getOrderStatus() == 4) {
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.GONE);

                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.GONE);
            } else if (mlist.get(position).getOrderStatus() == 5) {
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.GONE);

                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.GONE);
            } else if (mlist.get(position).getOrderStatus() == 6) {
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.GONE);
            } else if (mlist.get(position).getOrderStatus() == 7) {
                ((OneItemHolder) viewHolder).mDaijiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_bottom_jiedan.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mDaizhfuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).real_daifuwu.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mFuwuLayout.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancle.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mComplete.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mTuikuanRealLayout.setVisibility(View.VISIBLE);
                ((OneItemHolder) viewHolder).mBottomZhf.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mBottomDaifuw.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mRealeServic.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCancleRelat.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).mCompleteOrder.setVisibility(View.GONE);
                ((OneItemHolder) viewHolder).tuikuan_bottom.setVisibility(View.VISIBLE);
            }
            if (mlist.get(position).isCommented() == true) {
                ((OneItemHolder) viewHolder).my_dianpin.setText("我的点评");
            } else {
                ((OneItemHolder) viewHolder).my_dianpin.setText("去点评");
            }
            DecimalFormat format = new DecimalFormat("0.00");
            ((OneItemHolder) viewHolder).mYiyuan.setText("医院 : " + mlist.get(position).getOrderDTO().getHospitalName());
            ((OneItemHolder) viewHolder).mKeshi.setText("科室 : " + mlist.get(position).getOrderDTO().getOfficeName());
            ((OneItemHolder) viewHolder).mXiangm.setText(mlist.get(position).getOrderDTO().getServiceName());
            ((OneItemHolder) viewHolder).mJiuzhenName.setText(mlist.get(position).getOrderDTO().getPatientName());
            ((OneItemHolder) viewHolder).mServiceTime.setText(mlist.get(position).getOrderDTO().getPeriodStr());
            ((OneItemHolder) viewHolder).mOrderPrice.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).tuikuan_order_price.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).order_servie_price.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).cancle_order_price.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).order_price_jiedan.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).complete_order_price.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).order_fwu_price.setText(format.format(mlist.get(position).getPrice()));
            ((OneItemHolder) viewHolder).cancle_again_cancle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定再次预约吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            Bundle bundle = new Bundle();
                            bundle.putLong("orderId", mlist.get(position).getId());
                            openActivityWitchAnimation(AgainYuYueJiuzhenPersonActivity.class, bundle);
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).cancle_order_daizhfu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定要取消订单吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            JSONObject result = new JSONObject();
                            try {
                                result.put("userId", mUserId);
                                result.put("orderNo", mlist.get(position).getOrderNo());
                                result.put("id", mlist.get(position).getId());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            mPresenter.getCancle(mToken, result.toString());
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).mSubmitPay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定要支付吗?", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            orderId = mlist.get(position).getId();
                            hospitalId = mlist.get(position).getOrderDTO().getHospitalId();
                            hospitalName = mlist.get(position).getOrderDTO().getHospitalName();
                            mPresenter.getPayOrderMsg(mlist.get(position).getOrderNo(), mToken, mUserId);
                            mAdapter.notifyDataSetChanged();
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).shengqing_tuik.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定要退款吗?", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            mPresenter.getTuikuanMoney(mlist.get(position).getOrderNo(), mToken, mUserId);
                            mAdapter.notifyDataSetChanged();
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).tuikuan_again.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定再次预约吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            Bundle bundle = new Bundle();
                            bundle.putLong("orderId", mlist.get(position).getId());
                            openActivityWitchAnimation(AgainYuYueJiuzhenPersonActivity.class, bundle);
                            dialog.dismiss();
                        }
                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).order_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定要删除吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            mPresenter.getDeleteOrder(mToken, mlist.get(position).getId());
                            mlist.remove(position);
                            mAdapter.notifyItemRemoved(position);
                            mAdapter.notifyItemChanged(0, mlist.size());
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).cancle_order_jiedan.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定要退款吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            mPresenter.getTuikuanMoney(mlist.get(position).getOrderNo(), mToken, mUserId);
                            mAdapter.notifyDataSetChanged();
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).order_detials.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO: 2022/5/23 当状态为 2 的时候，表示待接单，跳转到地图界面
                    //  当状态为3 的时候，表示已接单，跳转到陪诊员详情界面
                    if (mlist.get(position).getOrderStatus() == 2) {
                        Bundle bundle = new Bundle();
                        bundle.putString("orderId", String.valueOf(mlist.get(position).getId()));
                        bundle.putLong("hospitalId", mlist.get(position).getOrderDTO().getHospitalId());
                        bundle.putString("hospitalName", mlist.get(position).getOrderDTO().getHospitalName());
                        openActivityWitchAnimation(WaitOrderMapActivity.class, bundle);
                    } else if (mlist.get(position).getOrderStatus() == 3) {
                        Bundle bundle = new Bundle();
                        bundle.putString("orderId", String.valueOf(mlist.get(position).getId()));
                        openActivityWitchAnimation(YuyueSuccessAcitivity.class, bundle);
                    }
                }
            });
            ((OneItemHolder) viewHolder).tober_xudan.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO: 2022/5/23 当状态为 2 的时候，表示待接单，跳转到地图界面
                    //  当状态为3 的时候，表示已接单，跳转到陪诊员详情界面
                    if (mlist.get(position).getOrderStatus() == 2) {
                        Bundle bundle = new Bundle();
                        bundle.putString("orderId", String.valueOf(mlist.get(position).getId()));
                        bundle.putLong("hospitalId", mlist.get(position).getOrderDTO().getHospitalId());
                        bundle.putString("hospitalName", mlist.get(position).getOrderDTO().getHospitalName());
                        openActivityWitchAnimation(WaitOrderMapActivity.class, bundle);
                    } else if (mlist.get(position).getOrderStatus() == 3) {
                        Bundle bundle = new Bundle();
                        bundle.putString("orderId", String.valueOf(mlist.get(position).getId()));
                        openActivityWitchAnimation(YuyueSuccessAcitivity.class, bundle);
                    }
                }
            });
            ((OneItemHolder) viewHolder).ckjc_fwu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("yiyuan", mlist.get(position).getOrderDTO().getHospitalName());
                    bundle.putString("keshi", mlist.get(position).getOrderDTO().getOfficeName());
                    bundle.putString("xiangm", mlist.get(position).getOrderDTO().getServiceName());
                    bundle.putString("jiuzhenren", mlist.get(position).getOrderDTO().getPatientName());
                    bundle.putString("shijian", mlist.get(position).getOrderDTO().getPeriodStr());
                    openActivityWitchAnimation(ServiceAccoMpanyingActivity.class, bundle);
                }
            });
            ((OneItemHolder) viewHolder).serive_again.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定再次预约吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            Bundle bundle = new Bundle();
                            bundle.putLong("orderId", mlist.get(position).getId());
                            openActivityWitchAnimation(AgainYuYueJiuzhenPersonActivity.class, bundle);
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
            ((OneItemHolder) viewHolder).my_dianpin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mlist.get(position).isCommented() == true) {
                        openActivityWitchAnimation(MyDianPingActivity.class);
                        ((OneItemHolder) viewHolder).my_dianpin.setText("我的点评");
                    } else {
                        ((OneItemHolder) viewHolder).my_dianpin.setText("去点评");
                        Bundle bundle = new Bundle();
                        bundle.putString("orderNo", mlist.get(position).getOrderNo());
                        bundle.putString("name", mlist.get(position).getOrderDTO().getPatientName());
                        bundle.putLong("orderId", mlist.get(position).getId());
                        bundle.putString("fuwuState", mlist.get(position).getOrderDTO().getServiceName());
                        bundle.putString("keshi", mlist.get(position).getOrderDTO().getOfficeName());
                        bundle.putString("shijian", mlist.get(position).getPlacedTimeStr());
                        openActivityWitchAnimation(OrderCommentActivity.class, bundle);
                    }
                }
            });
            ((OneItemHolder) viewHolder).again_yuyue_complete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    RoundCornerDialog dialog = new RoundCornerDialog(getActivity(), "确定再次预约吗？", "确定", "取消", new OnQuiteDialogClickListener() {
                        @Override
                        public void onConfirm(Dialog dialog) {
                            Bundle bundle = new Bundle();
                            bundle.putLong("orderId", mlist.get(position).getId());
                            openActivityWitchAnimation(AgainYuYueJiuzhenPersonActivity.class, bundle);
                            dialog.dismiss();
                        }

                        @Override
                        public void onCancel(Dialog dialog) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }
            });
        }

        @Override
        public int getItemCount() {
            return mlist == null ? 0 : mlist.size();
        }
    }

    /**
     * 第一个布局的Holder，要继承自RecyclerView.ViewHolder，这里你可以绑定控件
     */
    class OneItemHolder extends RecyclerView.ViewHolder {
        TextView mOrderNo, mYiyuan, mKeshi, cancle_order_daizhfu, order_price_jiedan,
                mXiangm, mJiuzhenName, mServiceTime, order_servie_price,
                mOrderPrice, mSubmitPay, shengqing_tuik, cancle_order_price, complete_order_price,
                order_number, order_fuwu_zhong, cancel_title, complet_order, my_dianpin, tuikuan_order_price,
                again_yuyue_complete, order_delete, cancle_again_cancle, ckjc_fwu, xudanfwu, tober_xudan,
                tuikuan_again, tuikuan_title, yifuk_title, cancle_order_jiedan, order_detials, serive_again, order_fwu_price;

        RelativeLayout mDaizhfuLayout, real_daifuwu, mFuwuLayout, tuikuan_bottom, mDaijiedan,
                mCancle, mComplete, mBottomZhf, mCompleteOrder, mTuikuanRealLayout,
                mBottomDaifuw, mCancleRelat, mRealeServic, real_bottom_jiedan;

        public OneItemHolder(@NonNull View itemView) {
            super(itemView);
            complete_order_price = (TextView) itemView.findViewById(R.id.complete_order_price);
            serive_again = (TextView) itemView.findViewById(R.id.serive_again);
            order_fwu_price = (TextView) itemView.findViewById(R.id.order_fwu_price);
            order_detials = (TextView) itemView.findViewById(R.id.order_detials);
            real_bottom_jiedan = (RelativeLayout) itemView.findViewById(R.id.real_bottom_jiedan);
            order_price_jiedan = (TextView) itemView.findViewById(R.id.order_price_jiedan);
            cancle_order_jiedan = (TextView) itemView.findViewById(R.id.cancle_order_jiedan);
            cancle_order_daizhfu = (TextView) itemView.findViewById(R.id.cancle_order_daizhfu);
            mOrderNo = (TextView) itemView.findViewById(R.id.obl_title);
            order_servie_price = (TextView) itemView.findViewById(R.id.order_servie_price);
            mYiyuan = (TextView) itemView.findViewById(R.id.obl_msg);
            mDaijiedan = (RelativeLayout) itemView.findViewById(R.id.real_yifukuan);
            yifuk_title = (TextView) itemView.findViewById(R.id.yifuk_title);
            tuikuan_title = (TextView) itemView.findViewById(R.id.tuikuan_title);
            mKeshi = (TextView) itemView.findViewById(R.id.order_keshi);
            mXiangm = (TextView) itemView.findViewById(R.id.order_xiagnm);
            mJiuzhenName = (TextView) itemView.findViewById(R.id.orer_xingm);
            mServiceTime = (TextView) itemView.findViewById(R.id.fuw_time);
            mOrderPrice = (TextView) itemView.findViewById(R.id.order_price);
            tuikuan_order_price = (TextView) itemView.findViewById(R.id.tuikuan_order_price);
            cancel_title = (TextView) itemView.findViewById(R.id.cancel_title);
            mSubmitPay = (TextView) itemView.findViewById(R.id.pay_order);
            complet_order = (TextView) itemView.findViewById(R.id.complet_order);
            order_fuwu_zhong = (TextView) itemView.findViewById(R.id.order_fuwu_zhong);
            order_number = (TextView) itemView.findViewById(R.id.order_number);
            cancle_order_price = (TextView) itemView.findViewById(R.id.cancle_order_price);
            mDaizhfuLayout = (RelativeLayout) itemView.findViewById(R.id.real_zhifu);
            real_daifuwu = (RelativeLayout) itemView.findViewById(R.id.real_daifuw);
            mFuwuLayout = (RelativeLayout) itemView.findViewById(R.id.real_fwuw);
            mCancle = (RelativeLayout) itemView.findViewById(R.id.realt_cancle);
            mComplete = (RelativeLayout) itemView.findViewById(R.id.real_compete);
            mTuikuanRealLayout = (RelativeLayout) itemView.findViewById(R.id.realt_tuikuan);

            mBottomZhf = (RelativeLayout) itemView.findViewById(R.id.real_bottom_zhfi);
            mBottomDaifuw = (RelativeLayout) itemView.findViewById(R.id.relat_bottom_daifuw);
            mRealeServic = (RelativeLayout) itemView.findViewById(R.id.relat_bottom_fwu);
            mCancleRelat = (RelativeLayout) itemView.findViewById(R.id.daizhif_canle);
            mCompleteOrder = (RelativeLayout) itemView.findViewById(R.id.daizhif_comp);
            tuikuan_again = (TextView) itemView.findViewById(R.id.tuikuan_again);
            my_dianpin = (TextView) itemView.findViewById(R.id.my_dianpin);
            again_yuyue_complete = (TextView) itemView.findViewById(R.id.again_yuyue_complete);
            order_delete = (TextView) itemView.findViewById(R.id.order_delete);
            cancle_again_cancle = (TextView) itemView.findViewById(R.id.cancle_again_cancle);
            ckjc_fwu = (TextView) itemView.findViewById(R.id.ckjc_fwu);
            shengqing_tuik = (TextView) itemView.findViewById(R.id.shengqing_tuik);
            tober_xudan = (TextView) itemView.findViewById(R.id.tober_xudan);
            tuikuan_bottom = (RelativeLayout) itemView.findViewById(R.id.tuikuan_bottom);
        }
    }
}
